<?php

namespace Common\Model;

class BookNewModel extends XuecheModel {

    protected $pk = 'book_id';
    protected $tableName = 'book_new';
    protected $fields = array(
            'book_id', 'article_id','article_name','update_time','piece_num','article_num'
        );

    /**
     * 清空数据缓存
     *
     */
    public function ClearAllCache() {

    }

    //缓存设置
    protected $_useCacheType = 'file';
    protected $_catheTime = 0;

    public function Validate($data) {
        if(empty($data['article_id']) || empty($data['article_name']) || empty($data['update_time']) || empty($data['book_id'])){
            return FALSE;
        }
        
        return true;
    }
    /**
     * 获取最新的章节名称
     * @param type $book_id
     * @return type
     */
    public function getNewArticle($book_id){
        if($book_id > 0){
            return $this->where("`{$this->pk}` = '{$book_id}'")->find();
        }
        return FALSE;
    }
    
    /**
     * 获取最新章节数和最新篇数
     * @param type $book_id
     * @return boolean
     */
    public function getNewNum($book_id){
        if($book_id > 0){
            return $this->where("`{$this->pk}` = '{$book_id}'")->field('piece_num,article_num')->find();
        }
        return FALSE;
    }

        public function saveNewArticle($data){
        if($this->Validate($data)){
            return $this->save($data);
        }
        return FALSE;
    }
    
    



}
